#include "mainwindow.h"
#include "glwidget.h"
#include <QtWidgets/QApplication>


auto getHwnd()
{
	struct Param
	{
		HWND hWorkerWTop{};

		HWND hWorkerW{};
		HWND hDefView{};
		HWND hFolderView{};
	} param;


	auto progman = ::FindWindowW(L"Progman", nullptr);


	DWORD_PTR result = 0;
	SendMessageTimeoutW(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, &result);


	EnumWindows([](HWND hwnd, LPARAM lParam) -> BOOL {
		auto param = (Param*)lParam;

		auto hDefview = ::FindWindowExW(hwnd, nullptr, L"SHELLDLL_DefView", nullptr);
		if(hDefview)
		{
			param->hWorkerWTop = hwnd;
			param->hDefView = hDefview;
			param->hFolderView = ::FindWindowExW(hDefview, nullptr, L"SysListView32", nullptr);
			param->hWorkerW = ::FindWindowExW(nullptr, hwnd, L"WorkerW", nullptr);
		}
		return TRUE;
	},
				(LPARAM)&param);

	return param;
}


int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	//mainWindow w;
	
	glWidget w;
	w.winId();

	::SetParent((HWND)w.winId(), getHwnd().hWorkerW);

	w.showMaximized();

	//SendMessage(getHwnd().hFolderView, 0, 0, 0);
	return a.exec();
}
